package cn.kevinking.auth.exception;

import cn.kevinking.common.constant.HttpConsts;
import cn.kevinking.common.exception.IBfzExceptionHandler;
import cn.kevinking.common.pojo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * handle auth exceptions globally
 *
 * @author kevinking
 * @since 13 Apr 2025
 */
@RestControllerAdvice
@Slf4j
public class BfzAuthExceptionHandler implements IBfzExceptionHandler {

	@ExceptionHandler(UsernameNotFoundException.class)
	public ResultVO<?> usernameNotFoundExceptionResolver(UsernameNotFoundException e) {
		return new ResultVO<>().code(HttpConsts.UNAUTHORIZED).msg(String.format("invalid username: %s", e.getMessage()));
	}
}
